/**
 * hash table demo
 */
package cn.netjava.softkid.chapter08;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

/**
 * @author softkid
 *
 */
public class HashtableDemo 
{
	private Hashtable<Integer,Object> htable;
	
	
	/**
	 * constructor method
	 * initialize a new hash table
	 */
	public HashtableDemo()
	{
		htable = new Hashtable<Integer,Object>();
	}
	/**
	 * add element to hash table
	 * @param key: an integer value
	 * @param value: an object value
	 */
	public void addElement(int key,Object value)
	{
		htable.put(key, value);
	}
	/**
	 * get value by key
	 * @param key: key to mapping value
	 */
	public void getValue(int key)
	{
		htable.get(key);
	}
	/**
	 * delete an element by key 
	 * @param key: an integer value
	 */
	public void deleteElement(int key)
	{
		htable.remove(key);
	}
	/**
	 * output all element in the hash table
	 */
	public void outputAllElements()
	{
		Set<Integer> s = htable.keySet();
		Iterator<Integer> iter = s.iterator();
		while(iter.hasNext())
		{
			System.out.println(htable.get(iter.next()));
		}
	}
	public void outputMapping()
	{
		Set s = htable.entrySet();
		Iterator iter = s.iterator();
		while(iter.hasNext())
		{
			System.out.println(iter.next());
		}
	}
}
